package com.example.kotlinstudy.类与对象

fun interface KRunnable {
    fun invoke()
}

//SAM转换
fun interface IntPredicate {
    fun accept(int: Int): Boolean
}

val isEven = object : IntPredicate {
    override fun accept(int: Int): Boolean {
        return int % 2 == 0
    }
}
val isEvenLambda = IntPredicate { it % 2 == 0 }
fun main() {
    println("Is 7 even? - ${isEvenLambda.accept(7)}")
    ::Printer
    println("Is 7 even? - ${isEven02(7)}")
}

interface Printer {
    fun print()
}

fun Printer(block: () -> Unit): Printer = object : Printer {
    override fun print() = block()
}

//函数式接口与类型别名比较
typealias IntPredicate02 = (i: Int) -> Boolean

val isEven02: IntPredicate02 = { it % 2 == 0 }